In [ ]:
# Only run this the VERY first time
!pip install metaknowledge
!pip install networkx
!pip install pandas
!pip install python-louvain
In [56]:
# Run this before you do anything else
import metaknowledge as mk
import networkx as nx
import pandas
import community
import webbrowser
In [57]:
# The line below is the most important line in the entire document.
# Make sure the filepath is set to the location where the WOS file is stored.
inputFile = "/Users/jilliananderson/Downloads/imetrics"
Next, we need to define some variables:
filepath should be set as the filepath to your isi file. networkType should be "CoCitation", "CoAuthor", or "Citation". nodeType must be set to one of "full", "original", "author", "journal", or "year".
In [60]:
networkType = "CoAuthor"
nodeType = "original"
In [ ]:
# This cell creates the network based on
# the variables you provided above.
RC = mk.RecordCollection(inputFile)
if networkType == "CoCitation":
net = RC.networkCoCitation(nodeType = nodeType, coreOnly=True)
directed = False
partition = community.best_partition(net)
elif networkType == "CoAuthor":
net = RC.networkCoAuthor()
directed = False
partition = community.best_partition(net)
elif networkType == "Citation":
net = RC.networkCitation(nodeType=nodeType, coreOnly=True)
directed = True
else:
print("Please ensure networkType has been set to one of the accepted values")
In [ ]:
# This code detects centrality measures for your network.
betweenness = nx.betweenness_centrality(net)
# closeness = nx.closeness_centrality(net) # <- Extra more complicated centrality
# eigenVect = nx.eigenvector_centrality(net) # <--/
In [62]:
for n in net.nodes():
if not directed:
betw = round(betweenness[n], 3)
comm = partition[n]
net.add_node(n, community=comm, betweenness=betw)
else:
betw = round(betweenness[n], 3)
net.add_node(n, community=comm, betweenness=betw)
In [ ]:
# This code writes two .csv files to your computer.
# One is the edgeList and the other is the node Attribute file
mk.writeGraph(net, "myNet")
In [53]:
%%writefile network.html
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>Network</title>
<link rel="stylesheet" href="http://networkslab.org/mkD3/styles.css">
<script src="https://d3js.org/d3.v4.js"></script>
<script src="http://networkslab.org/mkD3/mkd3.js"></script>
</head>
<body>
<script type = "text/javascript">
mkd3.networkGraph("myNet_edgeList.csv", "myNet_nodeAttributes.csv")
</script>
</body>
In [54]:
url = 'http://localhost:8888/files/network.html'
webbrowser.open(url)
Out[54]:
In [41]:
minYear = 1900
maxYear = 2016
rpysType = "StandardBar"
In [42]:
RC = mk.RecordCollection(inputFile)
rpys = RC.rpys(minYear=1900, maxYear=2016)
df = pandas.DataFrame.from_dict(rpys)
df.to_csv("standard_rpys.csv")
# Creating CitationFile
citations = RC.getCitations()
df = pandas.DataFrame.from_dict(citations)
df.to_csv("standard_citation.csv")
In [43]:
%%writefile standardBar.html
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>Title Here</title>
<link rel="stylesheet" href="http://networkslab.org/mkD3/styles.css">
<script src="https://d3js.org/d3.v4.js"></script>
<script src="http://networkslab.org/mkD3/mkd3.js"></script>
</head>
<body>
<script type = "text/javascript">
mkd3.standardBar("standard_rpys.csv", "standard_citation.csv")
</script>
</body>
In [44]:
url = 'http://localhost:8888/files/standardBar.html'
webbrowser.open(url)
Out[44]:
In [45]:
%%writefile standardLine.html
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>Title Here</title>
<link rel="stylesheet" href="http://networkslab.org/mkD3/styles.css">
<script src="https://d3js.org/d3.v4.js"></script>
<script src="http://networkslab.org/mkD3/mkd3.js"></script>
</head>
<body>
<script type = "text/javascript">
mkd3.standardLine("standard_rpys.csv", "standard_citation.csv")
</script>
</body>
In [46]:
url = 'http://localhost:8888/files/standardLine.html'
webbrowser.open(url)
Out[46]:
In [47]:
years = range(minYear, maxYear+1)
RC = mk.RecordCollection(inputFile)
# ***************************
# Create the multiRPYS file
# ***************************
dictionary = {'CPY': [],
"abs-deviation": [],
"num-cites": [],
"rank": [],
"RPY": []}
for i in years:
try:
RCyear = RC.yearSplit(i, i)
if len(RCyear) > 0:
rpys = RCyear.rpys(minYear=1900, maxYear=maxYear)
length = len(rpys['year'])
rpys['CPY'] = [i]*length
dictionary['CPY'] += rpys['CPY']
dictionary['abs-deviation'] += rpys['abs-deviation']
dictionary['num-cites'] += rpys['count']
dictionary['rank'] += rpys['rank']
dictionary['RPY'] += rpys['year']
except:
pass
df = pandas.DataFrame.from_dict(dictionary)
df.to_csv("multi_rpys.csv")
# ***************************
# Create the citation file
# ***************************
dictionary = {"author": [],
"journal": [],
"num-cites": [],
"RPY": [],
"CPY": []}
for i in years:
try:
RCyear = RC.yearSplit(i, i)
if len(RCyear) > 0:
citations = RCyear.getCitations()
length = len(citations['year'])
citations['CPY'] = [i]*length
dictionary['CPY'] += citations['CPY']
dictionary['author'] += citations['author']
dictionary['journal'] += citations['journal']
dictionary['num-cites'] += citations['num-cites']
dictionary['RPY'] += citations['year']
except:
pass
df = pandas.DataFrame.from_dict(dictionary)
df.to_csv("multi_citation.csv")
In [48]:
%%writefile multiRPYS.html
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>Title Here</title>
<link rel="stylesheet" href="http://networkslab.org/mkD3/styles.css">
<script src="https://d3js.org/d3.v4.js"></script>
<script src="http://networkslab.org/mkD3/mkd3.js"></script>
</head>
<body>
<script type = "text/javascript">
mkd3.multiRPYS("multi_rpys.csv", "multi_citation.csv")
</script>
</body>
In [49]:
url = 'http://localhost:8888/files/multiRPYS.html'
webbrowser.open(url)
Out[49]:
In [ ]: